/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 5e3 + 2, maxc = 26, mod = 998244353;

char s[maxn];

int f[maxn][maxc][maxc];

int main() {
  int n;
  cin >> n >> (s + 1);
  if (s[1] == '?' && s[2] == '?') {
    for (int i = 0; i < maxc; ++i) {
      for (int j = 0; j < maxc; ++j) {
        if (i == j) continue;
        f[2][i][j] = 1;
      }
    }
  } else if (s[1] == '?') {
    for (int i = 0; i < maxc; ++i) {
      if (i == s[2] - 'a') continue;
      f[2][s[2] - 'a'][i] = 1;
    }
  } else if (s[2] == '?') {
    for (int i = 0; i < maxc; ++i) {
      if (i == s[1] - 'a') continue;
      f[2][i][s[1] - 'a'] = 1;
    }
  } else if (s[1] != s[2]) {
    f[2][s[2] - 'a'][s[1] - 'a'] = 1;
  }
  for (int i = 3; i <= n; ++i) {
    if (s[i] == '?') {
      for (int j = 0; j < maxc; ++j) {
        for (int k = 0; k < maxc; ++k) {
          if (j == k) continue;
          for (int l = 0; l < maxc; ++l) {
            if (l == j) continue;
            f[i][j][k] += f[i - 1][k][l];
            f[i][j][k] %= mod;
          }
        }
      }
    } else {
      for (int k = 0; k < maxc; ++k) {
        if (s[i] - 'a' == k) continue;
        for (int l = 0; l < maxc; ++l) {
          if (s[i] - 'a' == l) continue;
          f[i][s[i] - 'a'][k] += f[i - 1][k][l];
          f[i][s[i] - 'a'][k] %= mod;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < maxc; ++i) {
    for (int j = 0; j < maxc; ++j) {
      ans += f[n][i][j];
      ans %= mod;
    }
  }
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("A - No Majority.in", "r", stdin);
  freopen("A - No Majority.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
